package com.jh3502.helper.function.login;

import android.support.annotation.NonNull;

import com.jh3502.helper.base.BaseCallback;
import com.jh3502.helper.base.BaseJson;
import com.jh3502.helper.base.BasePresenter;
import com.jh3502.helper.base.BaseView;
import com.jh3502.helper.utils.Utils;

import java.util.Map;

/**
 * @author harisucici
 * @date 2017/6/19
 */

public class LoginPresenter extends BasePresenter {
    LoginModel mLoginModel;

    LoginView mLoginView;

    public void setLoginView(LoginView mLoginView) {
        this.mLoginView = mLoginView;
    }

    //  登录
   /* public void toLogin(Map<String, Object> body) {
        mLoginView.showLoadingDialog();
        if (mLoginModel == null) {
            mLoginModel = new LoginModel(mLoginView.getActContext());
        }

        mLoginModel.login(body, new Callback<BaseJson>() {
            @Override
            public void onResponse(Call<BaseJson> call, Response<BaseJson> response) {
                BaseJson baseJson = response.body();
                EventBusHelper.handleBaseJson(baseJson);
                if (baseJson != null && baseJson.getCode() != null) {

                } else {
                    mLoginView.responseError(Constant.UNKNOW_ERROR_CODE, Constant.UNKNOW_ERROR_MESSAGE);
                }
            }

            @Override
            public void onFailure(Call<BaseJson> call, Throwable t) {

            }
        });
    }*/
    public void toLogin(Map<String, Object> body) {
//        mLoginView.showLoadingDialog();
        if (mLoginModel == null) {
            mLoginModel = new LoginModel(mLoginView.getActContext());
        }

        mLoginModel.login(body, new BaseCallback(mLoginView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                mLoginView.loginSuccess(Utils.getInstance().jso2map(baseJson.getObj().toString()));
            }
        });
    }


    @Override
    public void cancelCall() {

    }

    public interface LoginView extends BaseView {
        void loginSuccess(Map<String, Object> stringObjectMap);
    }
}
